package com.asen.commons.core.base.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * Model基类
 *
 * @author ls
 * @version 1.0
 * @date 2024-04-09
 */
public abstract class RootModel implements Serializable {

    public static final String EXTRA_VAR_NAME = "ext";

    @ApiModelProperty(value = "扩展参数", position = 9999)
    private Map<String, Object> ext = new HashMap<>();

    @JsonIgnore
    public void put(String key, Object value) {
        ext.put(key, value);
    }

    @JsonIgnore
    public Object get(String key) {
        return ext.get(key);
    }

    @JsonIgnore
    public String getString(String key) {
        Object val = get(key);
        return val == null ? null : val.toString();
    }

    @JsonIgnore
    public Integer getInteger(String key) {
        Object val = get(key);
        return val == null ? null : Integer.valueOf(val.toString());
    }

    @JsonIgnore
    public Long getLong(String key) {
        Object val = get(key);
        return val == null ? null : Long.valueOf(val.toString());
    }

    @JsonIgnore
    public BigDecimal getBigDecimal(String key) {
        Object val = get(key);
        return val == null ? null : new BigDecimal(val.toString());
    }

    @JsonIgnore
    public Object remove(String key) {
        if (this.ext == null) {
            return null;
        }
        return this.ext.remove(key);
    }

    public Map<String, Object> getExt() {
        return ext;
    }

    public void setExt(Map<String, Object> ext) {
        this.ext = ext;
    }

}
